package com.nadi.noda.islamicbuzzle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;

//Enum name collumn
class BuzzleMeta {
	public static String IMG = "img";
	public static String TITLE = "title";
	public static String DETAIL = "detaill";
}

public class Utils {
	// Separateur
	public static final String SEP_CSV = "~~";

	/*
	 * Helper method that loads the data from the states.csv and builds each csv row into a State object which then gets added to the
	 * Adapter.
	 */
	public static ArrayList<ContentValues> loadBuzzleFromFile(Context ctx) {
		try {
			// Get input stream and Buffered Reader for our data file.
			ArrayList<ContentValues> signerList = new ArrayList<ContentValues>();
			InputStream is = ctx.getAssets().open("buzzle.csv");
			BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			String line;
			// Read each line
			while ((line = reader.readLine()) != null) {
				// Split to separate the name from the capital
				String[] RowData = line.split(SEP_CSV);
				ContentValues singer = new ContentValues(3);
				singer.put(BuzzleMeta.IMG, RowData[0]);
				singer.put(BuzzleMeta.TITLE, RowData[1]);
				singer.put(BuzzleMeta.DETAIL, RowData[2]);
				signerList.add(singer);
			}
			return signerList;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}